package top.luckyluxcis.api;

import lombok.experimental.UtilityClass;
import top.luckyluxcis.RollApi;
import top.luckyluxcis.type.ExchangeRate;
import top.luckyluxcis.util.MapUtil;

import java.util.List;
import java.util.Map;

/**
 * @author Zhuang
 * @since 2023/9/25
 */
@SuppressWarnings("unused")
@UtilityClass
public class ExchangeRateUtil {
    private static final RollApi API = RollApi.getInstance();

    /**
     * 获取支持的货币编号列表
     *
     * @return {@link List}<{@link ExchangeRate.Config}>
     */
    public static List<ExchangeRate.Config> configs() {
        return API.get("/exchange_rate/configs", MapUtil.empty(), List.class, ExchangeRate.Config.class);
    }

    /**
     * 获取热门汇率列表信息
     *
     * @return {@link List}<{@link ExchangeRate}>
     */
    public static List<ExchangeRate> list() {
        return API.get("/exchange_rate/list", MapUtil.empty(), List.class, ExchangeRate.class);
    }

    /**
     * 获取热门汇率列表信息
     *
     * @return {@link List}<{@link ExchangeRate}>
     */
    public static List<ExchangeRate> hotList() {
        return ((ExchangeRate) API.get("/exchange_rate/list/v2", MapUtil.empty(), ExchangeRate.class)).getList();
    }

    /**
     * 查看指定货币编号的汇率信息
     *
     * @param from 源货币编号
     * @param to   目标货币编号
     * @return {@link ExchangeRate}
     */
    public static ExchangeRate search(String from, String to) {
        Map<String, Object> params = MapUtil.<String, Object>builder()
                .put("from", from)
                .put("to", to)
                .build();
        return API.get("/exchange_rate/aim", params, ExchangeRate.class);
    }
}
